#include "AnimatedButton.h"

#include <QGridLayout>

AnimatedButton::AnimatedButton(QWidget* parent) :
	QWidget(parent)
{
	_button = new QPushButton(this);
	_label = new QLabel(this);
	_movie = new QMovie(this);
	_label->setMovie(_movie);
	_button->setMaximumSize(1000,1000);

	showButton(true);

	setLayout(new QGridLayout(this));
	layout()->addWidget(_button);
	layout()->addWidget(_label);
	layout()->setContentsMargins(0,0,0,0);

	connect(_button, SIGNAL(clicked()), SIGNAL(clicked()));
}

void AnimatedButton::showButton(bool show)
{
	_button->setVisible(show);
	_label->setVisible(!show);
	if(show) _movie->stop();
	else _movie->start();
}

void AnimatedButton::setButtonIcon(QString icon)
{
	_button->setIcon(QIcon(icon));
	_button->setIconSize(QSize(_button->width()-4, _button->height()-4));
	_movie->setScaledSize(QSize(width()-8, height()-8));
}

void AnimatedButton::setAnimation(QString item)
{
	_movie->setFileName(item);
}

void AnimatedButton::setTooltip(QString tooltip)
{
	_button->setToolTip(tooltip);
}

